﻿#include "cdbmysqloper.h"

CDbMysqlOper::CDbMysqlOper(const QString &sConnectInfo, const QString &sConnectName)
    : CDbBaseOper(sConnectInfo)
{
    QString str = sConnectName;
    if(str.isEmpty())
    {
        str = "MySql : " + sConnectInfo.left(5);
    }
    if (QSqlDatabase::contains(str))
    {
        m_db = QSqlDatabase::database(str);
    }
    else
    {
        m_db = QSqlDatabase::addDatabase("QMYSQL", str);
    }
}

CDbMysqlOper::CDbMysqlOper(const CDataBaseConfig &cDbCfg)
    : CDbBaseOper(cDbCfg)
{
    QString str = cDbCfg.sConnectName;
    if(str.isEmpty())
    {
        str = "MySql : Oper";
    }
    if(QSqlDatabase::contains(str))
    {
        m_db = QSqlDatabase::database(str);
    }
    else
    {
        m_db = QSqlDatabase::addDatabase("QMYSQL", str);
    }
}

CDbMysqlOper::~CDbMysqlOper()
{
    QSqlDatabase::removeDatabase(m_dbCfg.sConnectName);
}
